#include "stdafx.h"
#include "LinkList.h"


#ifdef RUN_2_2

Node* findKthNode(LinkList ll, int k)
{
	if(!ll.head)
		return NULL;
	if(k <= 0)
		return NULL;
	int count = 1;
	Node* fastpt = ll.head;
	Node* slowpt = ll.head;

	while(count < k)
	{
		if(fastpt->next)
		{
			fastpt = fastpt->next;
			count++;
		}
		else
		{
			return NULL;
		}
	}
	while(fastpt->next)
	{
		fastpt = fastpt->next;
		slowpt = slowpt ->next;
	}
	return slowpt;

}

int main()
{
	LinkList ll;
	ll.appendToTail(1);
	ll.appendToTail(1);
	ll.appendToTail(2);
	ll.appendToTail(4);
	ll.appendToTail(3);
	ll.appendToTail(3);
	ll.appendToTail(3);
	ll.appendToTail(4);
	ll.print();

	std::cout << "The Kth Node:" << std::endl;
	Node* rt = findKthNode(ll, -1);
	if(rt)
		std::cout << rt->data << std::endl;
	else
		std::cout << "No Node" << std::endl;
	getchar();
}
#endif